home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / quarkpy / mapholes.py < prev    next >
Text File  |  2004-01-05  |  5KB  |  192 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Map editor "Line through hole" displayer
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/quarkpy/mapholes.py,v 1.6 2003/03/21 10:56:08 tiglari Exp $
  12.  
  13.  
  14.  
  15. #
  16. # This version can only load .lin files from Quake 2.
  17. #
  18.  
  19. import quarkx
  20. import qmacro
  21. import qtoolbar
  22. from maputils import *
  23. import mapeditor
  24. import mapoptions
  25.  
  26.  
  27.  
  28. class LinesDlg(qmacro.dialogbox):
  29.  
  30.     #
  31.     # dialog layout
  32.     #
  33.  
  34.     dfsep = 0.2
  35.     dlgflags = 0
  36.  
  37.     dlgdef = """
  38.       {
  39.         Style = "15"
  40.         Caption = "...found a hole..."
  41.         sep: = {Typ="S" Bold="0" Txt="There is a hole in your map."}
  42.         sep: = {Typ="S" Bold="0" Txt="Use the red line to locate it,"}
  43.         sep: = {Typ="S" Bold="0" Txt="and then click Ok below."}
  44.         close:py = {Txt="" }
  45.       }
  46.     """
  47.  
  48.     #
  49.     # __init__ initialize the object
  50.     #
  51.  
  52.     def __init__(self, form, editor):
  53.         self.editor = editor
  54.         src = quarkx.newobj(":")
  55.         qmacro.dialogbox.__init__(self, form, src,
  56.            close = qtoolbar.button(
  57.               self.close,
  58.               "click here to remove the arrow from your map",
  59.               ico_editor, 0,
  60.               "Ok, hide arrow"))
  61.  
  62.     def windowrect(self):
  63.         x1,y1,x2,y2 = quarkx.screenrect()
  64.         return (x2-180, 20, x2-15, 132)
  65.  
  66.     def onclose(self, dlg):
  67.         try:
  68.             del self.editor.LinesThroughHole
  69.             self.editor.invalidateviews()
  70.         except:
  71.             pass
  72.         qmacro.dialogbox.onclose(self, dlg)
  73.  
  74.  
  75. def LoadLinFile(editor, filename):
  76.     f = open(filename, "r")
  77.     data = f.readlines()
  78.     f.close()
  79.     pts = []
  80.     for txt in data:
  81.         try:
  82.             pts.append(quarkx.vect(txt))
  83.         except:
  84.             pass
  85.     if len(pts)>=1:
  86.         LinesDlg(editor.form, editor)
  87.         editor.LinesThroughHole = pts
  88.         editor.invalidateviews()
  89.  
  90.  
  91. def WateryChecker(editor):
  92.     "Returns a function that checks if a face is watery or not."
  93.  
  94.     watery = quarkx.setupsubset()["WateryTex"]
  95.     if watery:
  96.         #
  97.         # Quake 1 or Hexen II : faces whose texture name begins with
  98.         # a special symbol (e.g. a star "*") are not solid, so should be ignored.
  99.         #
  100.         filterfn = lambda p, w=watery: p.texturename[:1]==w
  101.     else:
  102.         #
  103.         # Quake 2 : watery faces are determined by "content" flags.
  104.         #
  105.         def filterfn(p, cachetex = {}, texsrc = editor.TexSource):
  106.             s = p["Contents"]
  107.             if s:
  108.                 try:
  109.                     return int(s) & 16777336     # some flags that define non-blocking polyhedrons
  110.                 except:
  111.                     return 0
  112.             try:
  113.                 return cachetex[p.texturename]
  114.             except:
  115.                 tex = p.texturename
  116.                 texobj = quarkx.loadtexture(tex, texsrc)
  117.                 if texobj is not None:
  118.                     try:
  119.                         texobj = texobj.disktexture
  120.                     except quarkx.error:
  121.                         texobj = None
  122.                 result = 1
  123.                 if texobj is not None:
  124.                     s = texobj["Contents"]
  125.                     try:
  126.                         result = int(s) & 16777336     # some flags that define non-blocking polyhedrons
  127.                     except:
  128.                         result = 0
  129.                 cachetex[tex] = result
  130.                 return result
  131.  
  132.     return filterfn
  133.  
  134.  
  135. def SearchForHoles(editor):
  136.     polys = filter(lambda p, watery=WateryChecker(editor): not watery(p.faces[0]), editor.Root.listpolyhedrons)
  137.     pts = quarkx.searchforholes(polys, editor.Root.listentities)
  138.     if pts is None:
  139.         quarkx.msgbox("No hole found.", MT_INFORMATION, MB_OK)
  140.     else:
  141.         LinesDlg(editor.form, editor)
  142.         editor.LinesThroughHole = pts
  143.         editor.invalidateviews()
  144.  
  145.  
  146.  
  147. def DrawLines(editor, view, oldFinishDrawing = mapeditor.MapEditor.finishdrawing):
  148.     try:
  149.         points = editor.LinesThroughHole
  150.         cv = view.canvas()
  151.         cv.pencolor = MapColor("Tag")
  152.         cv.penwidth = mapoptions.getLineThickness()
  153.         if len(points)==1:
  154.             pt0 = view.proj(points[0])
  155.             if pt0.visible:
  156.                 cv.line(pt0.x-5, pt0.y-5, pt0.x+6, pt0.y+6)
  157.                 cv.line(pt0.x-5, pt0.y+5, pt0.x+6, pt0.y-6)
  158.         else:
  159.             Arrow(cv, view, points[1], points[0])
  160.             pt0 = view.proj(points[1])
  161.             for p in points[2:]:
  162.                 pt1 = view.proj(p)
  163.                 cv.line(pt0, pt1)
  164.                 pt0 = pt1
  165.     except AttributeError:
  166.         pass
  167.     oldFinishDrawing(editor, view)
  168.  
  169.  
  170. mapeditor.MapEditor.finishdrawing = DrawLines
  171.  
  172. # ----------- REVISION HISTORY ------------
  173. #
  174. #
  175. #$Log: mapholes.py,v $
  176. #Revision 1.6  2003/03/21 10:56:08  tiglari
  177. #support for line-thickness specified by mapoption
  178. #
  179. #Revision 1.5  2003/03/19 22:27:10  tiglari
  180. #remove debug; there was no parsing error in this file (previous commit mistaken)
  181. #
  182. #Revision 1.4  2003/03/19 22:23:35  tiglari
  183. #fix bug in parsing
  184. #
  185. #Revision 1.3  2001/06/17 21:05:27  tiglari
  186. #fix button captions
  187. #
  188. #Revision 1.2  2000/06/02 16:00:22  alexander
  189. #added cvs headers
  190. #
  191. #
  192. #